package com.walle.sonar.export.report.reportdoc.module.ruleTop;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

import com.walle.sonar.export.report.reportdoc.module.issues.IssueItemInfo;
import com.walle.sonar.export.report.reportdoc.module.issues.Issueser;

public class RuleToper {
	
	public static List<RuleTopItemInfo> getRuleTop10() {
		
		Map<String, IssueItemInfo> issues = Issueser.getIssues();
		
		List<RuleTopItemInfo> ruleTopItemInfoList = new ArrayList<RuleTopItemInfo>() ;
		issues.forEach((key,issueItemInfo)->{
			
			String ruleCode = issueItemInfo.getRuleCode();
			ruleTopItemInfoList.add(new RuleTopItemInfo(ruleCode, new AtomicInteger(0))) ;
			
			// 循环检查自身合并相同记录
			ruleTopItemInfoList.forEach(ruleTopItemInfo->{
				if(ruleCode.equalsIgnoreCase(ruleTopItemInfo.getCode()))
					ruleTopItemInfo.getNum().getAndIncrement() ;
			});
			
			
			ruleTopItemInfoList.sort(new Comparator<RuleTopItemInfo>() {

				@Override
				public int compare(RuleTopItemInfo o1, RuleTopItemInfo o2) {
					// TODO Auto-generated method stub
					return 0;
				}
			});
			if (ruleTopItemInfoList.size()>10) 
				ruleTopItemInfoList.remove(10) ;
			
			
			
		});
		
		
		
		return null ;
	}
}
